<?php
namespace Admin\Controller;

// +----------------------------------------------------------------------
// | 文件 CircleController.class.php
// +----------------------------------------------------------------------
// | 说明 圈子管理
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

class CircleBanController extends BaseManageController {
    /**
    *控制操作的模型表
    */
    protected $modelName = 'CircleBan'; 

    /**
    *删除类型的设置 true|直接删除， false|设置数据状态
    */
    protected $is_del   = true;
    protected $base = [];
    /**
    *跳转的Url
    */
    // protected $jumpAct  = 'Circle/index';

    /**
    *操作index的前置操作
    *---设置数据筛选条件---
    */
    public function _before_index()
    {

        $circle_id = I('circle_id', 0, 'intval');
        if (!$circle_id){
            $this->error('缺少circle_id');
        }

        $circle = Service('Circle')->find($circle_id);
        $this->assign('circle', $circle);

        $map = [
            'circle_id' => (int)$circle_id
        ];

        $this->where = $map;

    }


    public function format_lists(&$lists) {
        foreach ($lists as &$item) {
             $item['user'] = event('User')->info($item['uid']);
        }
    }

    public function ajax_del($circle_id, $uid)
    {
        $map = [
            'uid'       => (int)$uid,
            'circle_id' => (int)$circle_id,
        ];
        $this->model->where($map)->delete();
        $this->success('操作成功');
    }

    public function _before_add()
    {
        $uid = I('uid',0,'intval');
        if (!$uid){
            $this->error('请填写UID');
        }


        if (!service('Users')->find($uid)){
            $this->error('用户不存在');
        }

        $map = [
            'uid'       => $uid,
            'circle_id' => I('circle_id', 0, 'intval'),
        ];

        if ($this->model->where($map)->count() > 0){
            $this->error('已经禁言了');
        }

    }


}


